<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title data-i18n="resources.title_DatasetInfo"></title>
    <script type="text/javascript" include="bootstrap" src="../js/include-web.js"></script>
    <style type="text/css">
        body {
            margin: 0;
            overflow: hidden;
            background: #fff;
            width: 100%;
            height: 100%
        }

        #map {
            position: absolute;
            width: 100%;
            height: 100%;
        }

        #toolbar {
            position: absolute;
            top: 50px;
            right: 10px;
            width: 300px;
            text-align: center;
            z-index: 100;
            border-radius: 4px;
        }

        /* 用户自定义-弹框内容样式 */
        #pop-content {
            right: 0 !important;
            padding-left: 20px;
            color: #000;
            word-wrap: break-word;
            margin-top: 10px;
        }
    </style>
</head>

<body>
    <div id="toolbar" class="panel panel-primary">
        <div class='panel-heading'>
            <h5 class='panel-title text-center' data-i18n="resources.title_DatasetInfo"></h5>
        </div>
        <div class='panel-body content'>
            <div class='panel'>
                <div class='input-group'>
                    <span class='input-group-addon' data-i18n="resources.text_Datasources"></span>
                    <select id='datasourcesSelect' class='form-control'></select>
                </div>
            </div>
            <div class='panel'>
                <div class='input-group'>
                    <span class='input-group-addon' data-i18n="resources.text_dataset"></span>
                    <select id='datasetsSelect' class='form-control'></select>
                </div>
            </div>
            <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_query"
                onclick="datasetsPrint()" />
        </div>
    </div>
    <div id="map"></div>
    <div id="popup" class="ol-popup">
        <a href="#" id="popup-closer" class="ol-popup-closer"></a>
        <div id="popup-content"></div>
    </div>
    <script type="text/javascript" include="infoWindow" src="../../dist/classic/include-classic.js"></script>
    <script>
        let host = window.isLocal ? window.server : "https://iserver.supermap.io";
        let map, layer,datasetsSelect,datasourcesSelect,
            url1 = host + "/iserver/services/map-world/rest/maps/World",
            url2 = host + "/iserver/services/data-world/rest/data";

        init()
        function init() {
            map = new SuperMap.Map("map", {
                controls: [
                    new SuperMap.Control.Zoom(),
                    new SuperMap.Control.Navigation({
                        dragPanOptions: {
                            enableKinetic: true
                        }
                    })]
            });
            layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", url1, {
                transparent: true, cacheEnabled: true
            }, { maxResolution: "auto" });
            layer.events.on({ "layerInitialized": addLayer });
            //初始化popup类
            markerPop = new SuperMap.InfoWindow(
                "marker"
            );
        }

        function addLayer() {
            map.addLayers([layer]);
            map.setCenter(new SuperMap.LonLat(0, 0), 0);
            dataSourcesService();
        }

        function dataSourcesService() {
            new SuperMap.REST.DatasourceService(url2).getDatasources(function (serviceResult) {
                datasourcesSelect = document.getElementById("datasourcesSelect");
                const datasourceNames = serviceResult.result.datasourceNames;
                for (let i = 0,len = serviceResult.result.datasourceNames.length; i < len; i++) {
                    datasourcesSelect.options[i] = new Option(datasourceNames[i], datasourceNames[i]);
                }
                const datasourceName = datasourcesSelect.value;
                datasetsService(datasourceName)
            });

        };

        //数据集信息
        function datasetsService(datasourceName) {
            new SuperMap.REST.DatasetService(url2).getDatasets(datasourceName, function (serviceResult) {
                const datasetNames = serviceResult.result.datasetNames;
                datasetsSelect = document.getElementById("datasetsSelect");
                for (let i = 0, len = datasetNames.length; i < len; i++) {
                    datasetsSelect.options[i] = new Option(datasetNames[i], datasetNames[i]);
                }
            });
        }

        function datasetsPrint() {
            const datasourceName = datasourcesSelect.value;
            const datasetName = datasetsSelect.value;
            new SuperMap.REST.DatasetService(url2).getDataset(datasourceName,datasetName, function (serviceResult) {
                markerPop.hide();
                markerPop.titleBox = true;
                markerPop.contentSize = new SuperMap.Size(240, 150);
                markerPop.render();
                markerPop.setContentHTML(null, '<div id="pop-content">' + "(" + resources.text_datasetInfoPrint + ")" + "<br>" +
                    "dataSourceName：" + JSON.stringify(serviceResult.result.datasetInfo.dataSourceName, null, 2) + "<br>" +
                    "description:" + JSON.stringify(serviceResult.result.datasetInfo.description, null, 2) + "<br>" +
                    "isFileCache:" + JSON.stringify(serviceResult.result.datasetInfo.isFileCache, null, 2) + "<br>" +
                    "name:" + JSON.stringify(serviceResult.result.datasetInfo.name, null, 2) + "<br>" +
                    "prjCoordSys:" + "(...)" + "<br>" + '</div>');
                markerPop.setLonLat(map.getCenter(), { x: 0, y: 0 });
                //添加弹窗到map图层
                map.addPopup(markerPop);
            });
        }

        // Feature取消选中事件响应
        function onFeatureUnselect() {
            markerPop.destroy();
        }
    </script>

</body>

</html>